import type { UserConfig } from 'vite';
import { resolve } from 'path';
import { createProxy, loadEnv } from './src/utils/vite';
const viteEnv = loadEnv();
const {
  VITE_BASE,
  VITE_DROP_CONSOLE,
  VITE_DROP_DEBUGGER,
  VITE_OUTPUT_DIR,
  VITE_PORT,
  VITE_PROXY,
} = viteEnv;
console.log(
  VITE_BASE,
  VITE_DROP_CONSOLE,
  VITE_DROP_DEBUGGER,
  VITE_OUTPUT_DIR,
  VITE_PORT,
  VITE_PROXY,
);
console.log(createProxy(VITE_PROXY));
function pathResolve(dir: string): string {
  return resolve(__dirname, '.', dir);
}

const viteConfig: UserConfig = {
  base: VITE_BASE,
  outDir: VITE_OUTPUT_DIR,
  port: VITE_PORT,
  open: true,
  https: false,
  ssr: false,
  optimizeDeps: {
    include: ['axios', 'element-plus'],
  },
  alias: {
    '/@/': pathResolve('src'),
  },
  minify: 'terser',
  terserOptions: {
    compress: {
      drop_console: VITE_DROP_CONSOLE,
      drop_debugger: VITE_DROP_DEBUGGER,
    },
  },
  esbuildTarget: 'es2020',
  cssPreprocessOptions: {
    scss: {
      additionalData: '@import "./src/styles/global/index.scss";',
    },
  },
  proxy: createProxy(VITE_PROXY),
};
export default viteConfig;
